package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo5Filter {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("filter")
    val sc = new SparkContext(conf)

    val linesRDD: RDD[String] = sc.textFile("data/students.txt")

    /**
     * filer: 过滤数据算子
     * 函数返回true保留数据，函数返回false过滤数据
     */

    //取出文科一班所有的学生
    val filterRDD: RDD[String] = linesRDD.filter(line => {
      //取出班级
      val clazz: String = line.split(",").last
      //返回布尔值
      "文科一班".equals(clazz)
    })

    filterRDD.foreach(println)

  }

}
